import { Icon } from "@ray-js/smart-ui";
import { View, Text } from "ray";
import React from "react";
import icTimer from '../../res/imgs/ic_timer.png';
import { useProps } from "@ray-js/panel-sdk";
export function MainDowTimerView() {
  let downTime = useProps(props => props.countdown_left); // 倒计时剩余时间，单位S,数值0-86400
  const min=Math.floor(downTime/60); //将s转化成分钟  119s -> 01:59
  // 计算 hourIndex 和 minuteIndex（只用一次）
  const hourIndex = Math.floor(min / 60);
  const minuteIndex = min % 60;
  console.log('MainDowTimerView', '显示的倒计时时间time：', downTime, ' hourIndex:', hourIndex, ' minuteIndex:'+minuteIndex+",min:"+min);

  const  hContent=hourIndex.toString().padStart(2, '0');
  const  mContent=minuteIndex.toString().padStart(2, '0');

  return (
    <>
      {(downTime > 0) && (<View className='view' style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'row' }}>
        <Icon name={icTimer} size="25px" />
        <Text style={{ color: 'white', fontSize: '16px', paddingLeft: '5rpx' }}>{hContent}:{mContent}</Text>
      </View>)}
    </>
  );
}

export default React.memo(MainDowTimerView);


